<%@page import="java.util.UUID"%>
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<%@ include file="/WEB-INF/pages/common/taglib.jsp" %>
<%
    String uuid = UUID.randomUUID().toString();
    request.setAttribute("uuid", uuid);
%>
<div class="row">
    <div class="col-md-12"  >
    	<div class="box box-primary">
    		<div class="box-header with-border">
    			<div class="box-tools">
    				<form id="form_${uuid }" class="form-inline" role="form">
					  <div class="form-group">
					    <input type="text" class="form-control input-sm" placeholder="用户名">
					  </div>
					  <div class="form-group">
					    <input type="text" class="form-control input-sm" placeholder="备注名">
					  </div>
					  <div class="form-group">
					  	<select class="form-control input-sm">
					  		<option>--</option>
					  		<option>男</option>
					  		<option>女</option>
					  	</select>
					  </div>
					  <button type="button" class="btn btn-primary input-sm">
					  	<span class="glyphicon glyphicon-search" aria-hidden="true"></span> 查询
					  </button>
					  <button type="button" class="btn btn-danger input-sm">
					  	<span class="glyphicon glyphicon-record" aria-hidden="true"></span> 重置
					  </button>
					</form>
    			</div>
    			<div class="box-title" id="toolbar_${uuid}">
    				<shiro:hasPermission name="WC_USER_INFO_SYNC">
			    		<button class="btn btn-sm btn-success syncInfoBtn">
			    			<span class="glyphicon glyphicon-retweet" aria-hidden="true"></span> 同步资料
			    		</button>
		    		</shiro:hasPermission>
    				<shiro:hasPermission name="WC_USER_INFO_SYNC_ALL">
			    		<button class="btn btn-sm btn-danger syncAllBtn">
			    			<span class="glyphicon glyphicon-retweet" aria-hidden="true"></span> 同步全部用户
			    		</button>
		    		</shiro:hasPermission>
    			</div>
    		</div>
    		<div class="box-body">
            	 <table id="wechatUserGrid_${uuid}"></table>
            </div>
    	</div>
    </div>
</div>
<script type="text/javascript">
$(function(){
	 var uuid = '${uuid}';
	 var toolbar =$("#toolbar_"+uuid);
	 
	 var grid = $("#wechatUserGrid_"+uuid).bootstrapTable({
     	url:ctx + "/wechat/user/listpage.do",
     	filterControl:false,
     	columns:[
			 {field: '_id', checkbox:true},
             {title: '用户名', field: 'nickNameDecode', width: "220px"},
             {title: '性别', field: 'sex', width: "50px", formatter:function(value,row){
            	 if(value==1){
            		 return '男'
            	 }else if(value==2){
            		 return '女';
            	 }else{
            		 return '未知';
            	 }
           	 }, align:'center', width: "50px"},
             {title: '备注名', field: 'remarkName', width: "150px"},
             {title: '标签列表', field: 'tagidList', width: "150px"},
             {title: '国', field: 'country', width: "100px", align:'center'},
             {title: '省', field: 'province', width: "100px", align:'center'},
             {title: '市', field: 'city', width: "150px", align:'center'},
             {title: '状态', field: 'subscribe', formatter:function(value,row){
            	 if(value==1){
            		 return '已关注';
            	 }else{
            		 return '未关注';
            	 }
           	 }, align:'center', width: "100px"},
             {title: '最后关注时间', field: 'subscribeTime', formatter:function(value,row){
            	 return webUtils.parseTimestamp(value,'yyyy-MM-dd hh:mm:ss');
           	 }, align:'center', width: "160px"},
             {title: '最新同步时间', field: 'syncTime', formatter:function(value,row){
            	 return webUtils.parseTimestamp(value,'yyyy-MM-dd hh:mm:ss');
           	 }, align:'center', width: "160px"},
             {title: '备注', field: 'remark'}
     	],
     	onClickRow:function(row){}
     });
	 
	 toolbar.find(".syncInfoBtn").click(function(){
		 var rows=grid.bootstrapTable("getSelections");
     	 if(rows && rows.length>0){
     		
     	 } else {
     		webUtils.alert("请选择需要同步的用户");
         }
     });
	 
	 toolbar.find(".syncAllBtn").click(function(){
		 webUtils.confirm("如果关注者数量过多需要的时间会比较长，确定要同步全部用户资料吗?", function(result) {
			if(result){
                $.post(ctx + "/wechat/user/syncAllUser.do",{},function(data){
                	 if (data.success) {
                		webUtils.alert(data.msg);
                		grid.bootstrapTable("refresh");
	                 } else {
	                    webUtils.alert(data.msg);
	                 }
	       		},'json');
			}
  		});
     });
});
</script>